package com.yvon.service.demo.netty.aio.client;

import lombok.extern.slf4j.Slf4j;

import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousSocketChannel;
import java.nio.charset.Charset;
import java.util.concurrent.Future;

/**
 * 客户端
 *
 * @author : Yvon
 * @since : 2022-11-11
 */
@Slf4j
public class AioClient {

    public static void main(String[] args) throws Exception {
        //面向流的侦听套接字的异步通道
        AsynchronousSocketChannel socketChannel = AsynchronousSocketChannel.open();
        Future<Void> future = socketChannel.connect(new InetSocketAddress("127.0.0.1", 63971));
        log.info("demo-netty client start done.");
        future.get();
        socketChannel.read(ByteBuffer.allocate(1024), null, new AioClientHandler(socketChannel, Charset.forName("GBK")));
        Thread.sleep(100000);
    }
}
